home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / IFF / Old_IFF_Packages / July_1992 / modules / getdisplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-06  |  5.4 KB  |  215 lines

  1.  
  2. /*----------------------------------------------------------------------*
  3.  * GETDISPLAY.C  Support routines for reading/displaying ILBM files.
  4.  * (IFF is Interchange Format File.)
  5.  *
  6.  * Based on code by Jerry Morrison and Steve Shaw, Electronic Arts.
  7.  * This software is in the public domain.
  8.  * Modified for iffparse.library by CBM 04/90
  9.  * This version for the Commodore-Amiga computer.
  10.  *
  11.  * 37.9  04/92 - use vp->ColorMap->Count instead of MAXAMCOLORREG
  12.  * 37.10 07/92 - use scr->RastPort.BitMap instead of &scr->BitMap
  13.  *                      for future compatibility
  14.  *----------------------------------------------------------------------*/
  15. #define INTUI_V36_NAMES_ONLY
  16.  
  17. #include "iffp/ilbm.h"
  18. #include "iffp/packer.h"
  19. #include "iffp/ilbmapp.h"
  20.  
  21. extern struct Library *GfxBase;
  22.  
  23. /* showilbm
  24.  *
  25.  * Passed an ILBMInfo initilized with with a not-in-use ParseInfo.iff
  26.  *   IFFHandle and desired propchks, collectchks, stopchks, and a filename,
  27.  *   will load and display an ILBM, initializing ilbm->Bmhd, ilbm->camg,
  28.  *   ilbm->scr, ilbm->win, ilbm->vp, ilbm->srp, ilbm->wrp,
  29.  *   ilbm->colortable, and ilbm->ncolors.
  30.  *
  31.  *   Note that ncolors may be more colors than you can LoadRGB4.
  32.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if you
  33.  *   change the colors yourself using 1.3/2.0 functions.
  34.  *
  35.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  36.  */
  37.  
  38. LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename)
  39. {
  40. LONG error = 0L;
  41.  
  42.     if(!(ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  43.  
  44.     if(!(error = openifile((struct ParseInfo *)ilbm, filename, IFFF_READ)))
  45.     {
  46.     D(bug("showilbm: openifile successful\n"));
  47.  
  48.     error = parseifile((struct ParseInfo *)ilbm,
  49.                 ID_FORM, ID_ILBM,
  50.                 ilbm->ParseInfo.propchks,
  51.                 ilbm->ParseInfo.collectchks,
  52.                 ilbm->ParseInfo.stopchks);
  53.  
  54.     if((!error)||(error == IFFERR_EOC)||(error == IFFERR_EOF))
  55.         {
  56.         D(bug("showilbm: parseifile successful\n"));
  57.  
  58.         if(contextis(ilbm->ParseInfo.iff,ID_ILBM,ID_FORM))
  59.         {
  60.             if(error = createdisplay(ilbm))
  61.             {
  62.             deletedisplay(ilbm);
  63.             }
  64.         }
  65.         else
  66.         {
  67.         message(SI(MSG_IFFP_NOILBM));
  68.         error = NOFILE;
  69.         }
  70.         }
  71.     if(error)    closeifile((struct ParseInfo *)ilbm);
  72.     }
  73.     return(error);
  74. }
  75.  
  76.  
  77. /* unshowilbm
  78.  *
  79.  * frees and closes everything alloc'd/opened by showilbm
  80.  * returns BOOL Success under V36 and above, always TRUE under <V36
  81.  */
  82. BOOL unshowilbm(struct ILBMInfo *ilbm)
  83. {
  84.     if(deletedisplay(ilbm))
  85.         {
  86.         closeifile((struct ParseInfo *)ilbm);
  87.         return(TRUE);
  88.         }
  89.     else return(FALSE);
  90. }
  91.  
  92.  
  93.  
  94. /* createdisplay
  95.  *
  96.  * Passed a initialized ILBMInfo with parsed IFFHandle (chunks parsed,
  97.  * stopped at BODY),
  98.  * opens/allocs the display and colortable, and displays the ILBM.
  99.  *
  100.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  101.  *   ilbm->vp,  ilbm->wrp, ilbm->srp and also ilbm->colortable and
  102.  *   ilbm->ncolors.
  103.  *
  104.  * Note that ncolors may be more colors than you can LoadRGB4.
  105.  *   Use MIN(ilbm->ncolors,vp->ColorMap->Count) for color count if you
  106.  *   change the colors yourself using 1.3/2.0 functions.
  107.  *
  108.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  109.  */
  110.  
  111. LONG createdisplay(struct ILBMInfo *ilbm)
  112.     {
  113.     int error;
  114.  
  115.     D(bug("createdisplay:\n"));
  116.  
  117.     error             = getdisplay(ilbm);
  118.  
  119.     D(bug("createdisplay: after getdisplay, error = %ld\n", error));
  120.  
  121.     if(!error) 
  122.         error     = loadbody(ilbm->ParseInfo.iff,
  123.                     ilbm->scr->RastPort.BitMap,&ilbm->Bmhd);
  124.  
  125.     D(bug("createdisplay: after loadbody, error = %ld\n", error));
  126.  
  127.     if(!error)
  128.         { 
  129.         if(!(getcolors(ilbm)))
  130.            LoadRGB4(ilbm->vp, ilbm->colortable,
  131.                 MIN(ilbm->ncolors,ilbm->vp->ColorMap->Count));
  132.         }
  133.     if(error)  deletedisplay(ilbm);
  134.     return(error);
  135.     }
  136.  
  137.  
  138. /* deletedisplay
  139.  *
  140.  * closes and deallocates created display and colors
  141.  * returns BOOL Success under V36 and above, always TRUE under <V36
  142.  */
  143. BOOL deletedisplay(struct ILBMInfo *ilbm)
  144.     {
  145.     if(freedisplay(ilbm))
  146.         {
  147.         freecolors(ilbm);
  148.         return(TRUE);
  149.         }
  150.     else return(FALSE);
  151.     }
  152.  
  153.  
  154.  
  155. /* getdisplay
  156.  *
  157.  * Passed an initialized ILBMInfo with a parsed IFFHandle (chunks parsed,
  158.  * stopped at BODY),
  159.  * gets the dimensions and mode for the display and calls the external
  160.  * routine opendisplay().  Our opendisplay() is in the screen.c
  161.  * module.  It opens a 2.0 or 1.3, ECS or non-ECS screen and window.
  162.  * It also does 2.0 overscan centering based on the closest user prefs.
  163.  *
  164.  * If successful, sets up ilbm->Bmhd, ilbm->camg, ilbm->scr, ilbm->win,
  165.  *   ilbm->vp, ilbm->wrp, ilbm->srp
  166.  *
  167.  * Returns 0 for success or an IFFERR (libraries/iffparse.h)
  168.  */
  169. LONG getdisplay(struct ILBMInfo *ilbm)
  170.     {
  171.     struct IFFHandle *iff;
  172.     BitMapHeader *bmhd;
  173.     ULONG                modeid;
  174.     UWORD                wide, high, deep;
  175.  
  176.  
  177.     if(!(iff=ilbm->ParseInfo.iff))    return(CLIENT_ERROR);
  178.  
  179.     if(!(bmhd = (BitMapHeader *)findpropdata(iff, ID_ILBM, ID_BMHD)))
  180.         {
  181.         message (SI(MSG_IFFP_NOBMHD));
  182.         return(IFFERR_SYNTAX);
  183.         }
  184.  
  185.     *(&ilbm->Bmhd)    = *bmhd;
  186.  
  187.         wide = (RowBytes(bmhd->w)) >= (RowBytes(bmhd->pageWidth)) ?
  188.                 bmhd->w : bmhd->pageWidth;
  189.         high = MAX(bmhd->h, bmhd->pageHeight);
  190.         deep = MIN(bmhd->nPlanes,MAXAMDEPTH);
  191.  
  192.     ilbm->camg = modeid = getcamg(ilbm);
  193.  
  194.     /*
  195.      * Open the display
  196.      */
  197.     if(!(opendisplay(ilbm,wide,high,deep,modeid)))
  198.         {
  199.         message(SI(MSG_IFFP_NODISPLAY));
  200.         return(1);
  201.         }
  202.     return(0);
  203.     }
  204.  
  205.  
  206. /* freedisplay
  207.  *
  208.  * closes and deallocates display from getdisplay (not colors)
  209.  * returns BOOL Success under V36 and above, always TRUE under <V36
  210.  */
  211. BOOL freedisplay(struct ILBMInfo *ilbm)
  212.     {
  213.     return(closedisplay(ilbm));
  214.     }
  215.